#!/bin/bash

deploy_arm() {
  cd /tmp
  curl -O $1
  tar -zxvf jdk-8u202-linux-arm64-vfp-hflt.tar.gz
  mv jdk1.8.0_202 /usr/local/jdk
  rm -rf jdk-8u202-linux-arm64-vfp-hflt.tar.gz
}

deploy_amd() {
  cd /tmp
  curl -O $1
  tar -zxvf jdk-8u333-linux-x64.tar.gz
  mv jdk1.8.0_333 /usr/local/jdk
  rm -rf jdk-8u333-linux-x64.tar.gz
}

if [ "$1" == "arm64" ]; then
  deploy_arm 'ftp://admin:ci_CcXx_4202ftp@10.20.140.138/tools/jdk/jdk-8u202-linux-arm64-vfp-hflt.tar.gz'
else
  deploy_amd 'ftp://admin:ci_CcXx_4202ftp@10.20.140.138/tools/jdk/jdk-8u333-linux-x64.tar.gz'
fi

echo "export JAVA_HOME=/usr/local/jdk" >> ~/.bashrc
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bashrc

source ~/.bashrc
java -version